import Vue from "vue";
import store from "./store";
import Router from "vue-router";
import Home from "./views/Home.vue";
import SubmitSucess from "./views/Submit-Sucess.vue";
import SubmitFail from "./views/Submit-Fail.vue";

const ShaoMa = () => import("./views/ShaoMa.vue");
const LogPage = () => import("./views/log-page.vue");
const SjLists = () => import("./views/Sj-Lists.vue");
const SjForma = () => import("./views/Sj-Forma.vue");
const SjFormb = () => import("./views/Sj-Formb.vue");
const SjFormc = () => import("./views/Sj-Formc.vue");
const SjFormd = () => import("./views/Sj-Formd.vue");
const SjSubmit = () => import("./views/Sj-Submit.vue");
const SjView = () => import("./views/Sj-Submit-View.vue");

Vue.use(Router, store);

export default new Router({
  // mode: "history",
  mode: "hash",
  base: process.env.BASE_URL,
  routes: [
    {
      path: "/",
      name: "home",
      component: Home
    },
    {
      path: "/shaoma",
      name: "shaoma",
      component: ShaoMa,
      meta: {
        keepAlive: true,
        title: "扫描二维码"
      },
      beforeEnter: (to, from, next) => {
        if (store.state.isLogin === 0) {
          next({
            name: "logPage",
            query: { redirect: to.fullPath }
          });
        } else {
          next();
        }
      }
    },
    {
      path: "/logPage",
      name: "logPage",
      component: LogPage,
      meta: {
        title: "登录"
      }
    },
    {
      path: "/sjlists",
      name: "sjlists",
      component: SjLists,
      meta: {
        keepAlive: true
      },
      beforeEnter: (to, from, next) => {
        if (store.state.isLogin === 0) {
          next({
            name: "logPage",
            query: { redirect: to.fullPath }
          });
        } else {
          next();
        }
      }
    },
    {
      path: "/sjforma",
      name: "sjforma",
      component: SjForma,
      meta: {
        keepAlive: true
      },
      beforeEnter: (to, from, next) => {
        if (store.state.isLogin === 0) {
          next({
            name: "logPage",
            query: { redirect: to.fullPath }
          });
        } else {
          next();
        }
      }
    },
    {
      path: "/sjformb",
      name: "sjformb",
      component: SjFormb,
      meta: {
        keepAlive: true
      },
      beforeEnter: (to, from, next) => {
        if (store.state.isLogin === 0) {
          next({
            name: "logPage",
            query: { redirect: to.fullPath }
          });
        } else {
          next();
        }
      }
    },
    {
      path: "/sjformc",
      name: "sjformc",
      component: SjFormc,
      meta: {
        keepAlive: true
      },
      beforeEnter: (to, from, next) => {
        if (store.state.isLogin === 0) {
          next({
            name: "logPage",
            query: { redirect: to.fullPath }
          });
        } else {
          next();
        }
      }
    },
    {
      path: "/sjformd",
      name: "sjformd",
      component: SjFormd,
      meta: {
        keepAlive: true
      },
      beforeEnter: (to, from, next) => {
        if (store.state.isLogin === 0) {
          next({
            name: "logPage",
            query: { redirect: to.fullPath }
          });
        } else {
          next();
        }
      }
    },
    {
      path: "/sjSubmit",
      name: "sjSubmit",
      component: SjSubmit,
      beforeEnter: (to, from, next) => {
        if (store.state.isLogin === 0) {
          next({
            name: "logPage",
            query: { redirect: to.fullPath }
          });
        } else if (from.name === "submitSucess") {
          next({
            name: "sjlists"
          });
        } else {
          next();
        }
      }
    },
    {
      path: "/sjView/:Id",
      name: "sjView",
      component: SjView,
      beforeEnter: (to, from, next) => {
        if (store.state.isLogin === 0) {
          next({
            name: "logPage",
            query: { redirect: to.fullPath }
          });
        } else {
          next();
        }
      }
    },
    {
      path: "/submitSucess",
      name: "submitSucess",
      component: SubmitSucess
    },
    {
      path: "/submitFail",
      name: "submitFail",
      component: SubmitFail
    }
  ]
});
